package com.lanxin.oa.approve.controller;
import com.lanxin.bean.LcFlow;
import com.lanxin.bean.LcNode;
import com.lanxin.oa.approve.service.NodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/node")
public class NodeController {

    @Autowired
    private NodeService nodeService;

    @RequestMapping("/listNode")
    public ModelAndView listNode(Integer flowid){
        ModelAndView mv=new ModelAndView();
        LcFlow lcFlow=nodeService.selectLcFlowById(flowid);
        List<LcNode> listNode=nodeService.selectLcNodeById(flowid);
        mv.addObject("lcFlow",lcFlow);
        mv.addObject("listNode",listNode);
        mv.setViewName("../view/approve/editnode.jsp");
        return mv;
    }



    @RequestMapping("/editNode")
    public ModelAndView editNode(LcNode node){
        ModelAndView mv=new ModelAndView();
         nodeService.editLcNode(node);
        mv.setViewName("redirect:/node/listNode?flowid="+node.getParentid());
        return mv;
    }

    @RequestMapping("/deleteNode")
    @ResponseBody
    public boolean deleteNode(Integer oid) {
        return nodeService.deleteNode(oid);
    }


}
